
#ifndef RAYTRACING_H
#define RAYTRACING_H

#include <math.h>

#define my_cross(res, v1, v2) \
			res[0] = v1[1]*v2[2] - v1[2]*v2[1]; \
			res[1] = v1[2]*v2[0] - v1[0]*v2[2];	\
			res[2] = v1[0]*v2[1] - v1[1]*v2[0];

//#define dot(v1, v2) (v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2])

inline float dot(const float* v1, const float* v2){
	return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}

inline void Normalize(float* v){
	float mag = sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
	if( mag == 0)
		return;
	float inv_mag = 1.0f / mag;
	v[0] *= inv_mag;
	v[1] *= inv_mag;
	v[2] *= inv_mag;
}

inline float* Cross(float* v1, float*v2){
	float* res = new float[3];
	res[0] = v1[1]*v2[2] - v1[2]*v2[1];
	res[1] = v1[2]*v2[0] - v1[0]*v2[2];
	res[2] = v1[0]*v2[1] - v1[1]*v2[0];
	return res;
}

inline void Cross(float* res, float* v1, float*v2){
	res[0] = v1[1]*v2[2] - v1[2]*v2[1];
	res[1] = v1[2]*v2[0] - v1[0]*v2[2];
	res[2] = v1[0]*v2[1] - v1[1]*v2[0];
}


bool TraceLine(const float orig[3], const float dir[3], const float* tri, float* dist);


#endif
